import {nextTick, ref} from 'vue'
import {defineStore} from 'pinia'
import {cacheKeys} from '@/stores/constant/cacheKey'

export const useAppStore = defineStore(cacheKeys.APP, () => {

			const isAlive = ref(true)

			const refreshApp = () => {
				isAlive.value = false
				nextTick().then(() => {
					isAlive.value = true
				})
			}

			const resetAppStore = () => {
				isAlive.value = true
			}

			return {
				isAlive: isAlive,
				refreshApp: refreshApp,
				resetAppStore: resetAppStore
			}
		},
		{
			persist: {
				key: cacheKeys.APP,
				storage: window.sessionStorage
			}
		}
)
